import { handleFiles, stopUpload } from "./upload.js";
import { handleDownload, stopDownload } from "./download.js";

const pauseDownload = document.querySelector("#PauseDownload");
const startDownload = document.querySelector("#StartDownload");

// 暂停任务
pauseDownload.addEventListener("click", async () => {
  stopDownload();
  stopUpload();
});

// 下载文件
startDownload.addEventListener("click", () => {
  handleDownload(); // 开始处理下载
});

// 上传文件
const dropzone = document.getElementById("dropzone");
const fileInput = document.getElementById("fileInput");

fileInput.addEventListener("change", function () {
  handleFiles(this.files);
});

dropzone.addEventListener("drop", function (event) {
  event.preventDefault();
  handleFiles(event.dataTransfer.files);
});

dropzone.addEventListener("dragover", function (event) {
  event.preventDefault();
});

const initDb = document.querySelector("#init-db");

initDb.addEventListener("click", () => {
  console.log("initDb");

  window.electronAPI.initDownloadTasks();
});
